import re, io
p = r'static/js/admin.js'
s = io.open(p, 'r', encoding='utf-8').read()
mt = re.search(r"template:\s*`([\s\S]*?)`", s)
if mt:
    tpl = mt.group(1)
    start, end = mt.span(1)
    # prepare insertion near end of orders section
    o_start = tpl.find("<section v-if=\"activeTab === 'orders'\"")
    if o_start != -1:
        o_end = tpl.find("</section>", o_start)
        if o_end != -1:
            extra = "\n        <div class=\"pager-row\" style=\"display:flex; gap:12px; align-items:center; margin-top:12px;\">\n          <span>每页条数:</span>\n          <select v-model=\"ordersPagination.pageSize\" @change=\"handleOrdersPageSizeChange\">\n            <option :value=\"10\">10</option>\n            <option :value=\"12\">12</option>\n            <option :value=\"20\">20</option>\n            <option :value=\"50\">50</option>\n            <option :value=\"100\">100</option>\n          </select>\n          <button class=\"btn\" type=\"button\" @click=\"changeOrdersPage(-1)\" :disabled=\"ordersPagination.pageIndex <= 1\">上一页</button>\n          <span>第 {{ ordersPagination.pageIndex }} / {{ ordersPagination.pages }} 页</span>\n          <button class=\"btn\" type=\"button\" @click=\"changeOrdersPage(1)\" :disabled=\"ordersPagination.pageIndex >= ordersPagination.pages\">下一页</button>\n          <button class=\"btn secondary\" type=\"button\" @click=\"toggleOrdersRaw\">{{ showOrdersRaw ? '隐藏原始结构' : '查看原始标准结构' }}</button>\n        </div>\n        <div v-if=\"showOrdersRaw\" class=\"log-block\" style=\"max-height: 280px; margin-top: 12px;\">\n          <pre class=\"log-line\">{{ JSON.stringify(ordersRaw && ordersRaw.recordList ? ordersRaw.recordList : [], null, 2) }}</pre>\n        </div>\n"
            newtpl = tpl[:o_end] + extra + tpl[o_end:]
            s = s[:start] + newtpl + s[end:]
            io.open(p, 'w', encoding='utf-8', newline='\n').write(s)
            print('TPL_UPDATED')
        else:
            print('ORDERS_END_NOT_FOUND')
    else:
        print('ORDERS_START_NOT_FOUND')
else:
    print('TPL_NOT_FOUND')
